home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 116_01.zip / ENGLISH.C < prev    next >
Text File  |  1993-06-19  |  2KB  |  152 lines

  1.  
  2. /*  ENGLISH.C   no mod for V 1.43  */
  3. #include "advent.h"
  4.  
  5. /*
  6.     Analyze a two word sentence
  7. */
  8. english()
  9. {
  10.  
  11.     char *msg;
  12.     int type1,type2,val1,val2;
  13.  
  14.     verb=object=motion=0;
  15.     type2=val2=-1;
  16.     type1=val1=-1;
  17.     msg="bad grammar...";
  18.     getin();
  19.     if(!analyze(word1,&type1,&val1))
  20.         return 0;
  21.     if(type1==2 && val1==SAY) {
  22.         verb=SAY;
  23.         object=1;
  24.         return 1;
  25.     }
  26.     if(strcmp(word2,""))
  27.         if(!analyze(word2,&type2,&val2))
  28.             return 0;
  29.     /* check his grammar */
  30.     if(type1==3) {
  31.         rspeak(val1);
  32.         return 0;
  33.     }
  34.     else if(type2==3) {
  35.         rspeak(val2);
  36.         return 0;
  37.     }
  38.     else if(type1==0) {
  39.         if(type2==0) {
  40.             printf("%s\n",msg);
  41.             return 0;
  42.         }
  43.         else
  44.             motion=val1;
  45.     }
  46.     else if(type2==0)
  47.         motion=val2;
  48.     else if(type1==1) {
  49.         object=val1;
  50.         if(type2==2)
  51.             verb=val2;
  52.         if(type2==1) {
  53.             printf("%s\n",msg);
  54.             return 0;
  55.         }
  56.     }
  57.     else if(type1==2) {
  58.         verb=val1;
  59.         if(type2==1)
  60.             object=val2;
  61.         if(type2==2) {
  62.             printf("%s\n",msg);
  63.             return 0;
  64.         }
  65.     }
  66.     else
  67.         bug(36);
  68.     return 1;
  69. }
  70.  
  71.  
  72. /*
  73.         Routine to analyze a word.
  74. */
  75. analyze(word,type,value)
  76. char *word;
  77. int *type,*value;
  78. {
  79.     int wordval,msg,i;
  80.  
  81.     /* make sure I understand */
  82.     if((wordval=vocab(word,0))==-1) {
  83.         switch(rand()%3) {
  84.         case 0:
  85.             msg=60;
  86.             break;
  87.         case 1:
  88.             msg=61;
  89.             break;
  90.         default:
  91.             msg=13;
  92.         }
  93.         rspeak(msg);
  94.         return(0);
  95.     }
  96.     *type = wordval/1000;
  97.     *value = wordval%1000;
  98.     return 1;
  99. }
  100.  
  101. /*
  102.     routine to get two words of input
  103.     and convert them to lower case
  104. */
  105. getin()
  106. {
  107.     char *cptr,*bptr;
  108.     char linebuff[65];
  109.  
  110.     putchar(0x80+'>');
  111.     word1[0]=word2[0]='\0';
  112.     bptr=linebuff;
  113.     gets(linebuff);
  114.     skipspc(&bptr);
  115.     getword(&bptr,word1);
  116.     if(!*bptr)
  117.         return;
  118.     while(!isspace(*bptr)) {
  119.         if(!*bptr++)
  120.             return;
  121.     }
  122.     skipspc(&bptr);
  123.     getword(&bptr,word2);
  124. }
  125.  
  126. /*
  127.     Routine to extract one word from a buffer
  128. */
  129. getword(buff,word)
  130. char **buff,*word;
  131. {
  132.     int i;
  133.  
  134.     for(i=0;i<WORDSIZE;++i) {
  135.         if(!**buff || isspace(**buff)) {
  136.             *word='\0';
  137.             return;
  138.         }
  139.         *word++=tolower(*(*buff)++);
  140.     }
  141.     *--word='\0';
  142. }
  143.  
  144. /*
  145.     Routine to skip spaces
  146. */
  147. skipspc(buff)
  148. char **buff;
  149. {
  150.     while(isspace(**buff)) ++(*buff);
  151. }
  152.